<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="type1"
          @click="handleOutPut"
          v-hasPermi="['output:cjmFinish:allOut']"
        >
          一键出库
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="type1"
          @click="handlePost"
          v-hasPermi="['output:cjmFinish:post']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['output:cjmOpen:export']"
        >
          导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExportMx"
          v-hasPermi="['output:cjmOpen:mxExport']"
        >
          导出明细
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      :cell-style="iCellStyle"
      v-loading="loading"
      :data="cjmOpenList"
      :height="tableH"
      @row-click="clickRwm"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" type="index" min-width="5%" align="center" />
      <el-table-column
        label="借料单号"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmDjbh"
      />
      <el-table-column
        label="借料日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cjmRq"
        min-width="10%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cjmRq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="借料仓库"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.cjmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="借料厂商"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmCsdm"
      >
        <template #default="scope">
          <dict-tag :options="allCsOptions" :value="scope.row.cjmCsdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmDesc"
      />
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmNgdesc"
      />
      <el-table-column
        label="开单人员"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmJlry"
      />
      <el-table-column
        label="开单日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cjmJlrq"
        min-width="10%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cjmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批准人员"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmPzry"
      />
      <el-table-column
        label="批准日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cjmPzrq"
        min-width="10%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cjmPzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cjmGzrq"
        min-width="10%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cjmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        min-width="10%"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handlePrint(scope.row)"
            v-hasPermi="['output:cjmFinish:print']"
            >单据打印</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!--    需要打印的东西-->
    <el-dialog
      v-model="printDiag"
      :close-on-click-modal="false"
      width="95b2px"
      append-to-body
    >
      <section ref="print">
        <el-table
          border
          style="width: 100%"
          :data="cjmChildrenList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="武汉市衡德实业有限公司对外借料出库单">
            <el-table-column label="厂商" width="135">
              <el-table-column label="退货仓库" width="135">
                <el-table-column
                  label="物料编码"
                  align="center"
                  prop="cjdWldm"
                  width="135"
                ></el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printDjbh" width="135">
              <el-table-column :label="printCkdm" width="135">
                <el-table-column
                  label="物料名称规格"
                  align="center"
                  prop="itmPmgg"
                  width="355"
                ></el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printRq" width="300">
              <el-table-column label="单据编码" width="100">
                <el-table-column
                  label="客户编码"
                  width="130"
                  prop="cjdKhbm"
                ></el-table-column>
                <el-table-column
                  label="单位"
                  :show-overflow-tooltip="true"
                  width="70"
                  align="center"
                  prop="itmDw"
                >
                  <template #default="scope">
                    <dict-tag
                      :options="unitFlagOptions"
                      :value="scope.row.itmDw"
                    />
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printRy" width="100">
              <el-table-column :label="printDh" width="100">
                <el-table-column
                  label="数量"
                  align="center"
                  prop="cjdCksl"
                  width="100"
                ></el-table-column>
                <el-table-column label="备注" width="120"></el-table-column>
              </el-table-column>
            </el-table-column>
          </el-table-column>
        </el-table>
        <div
          slot="footer"
          class="dialog-footer no-print"
          style="margin-top: 10px; display: flex; justify-content: flex-end"
        >
          <el-button type="primary" class="no-print" @click="printData"
            >打 印</el-button
          >
          <el-button class="no-print" @click="cancel">取 消</el-button>
        </div>
      </section>
    </el-dialog>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="cjmChildrenList"
      :height="tableHChild"
      :cell-style="iCellStyle2"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" min-width="4%" align="center" />
      <el-table-column
        label="物料代码"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdWldm"
      />
      <el-table-column
        label="规格描述"
        :show-overflow-tooltip="true"
        min-width="20%"
        prop="itmPmgg"
      />
      <el-table-column
        label="客户编码"
        :show-overflow-tooltip="true"
        min-width="10%"
        prop="cjdKhbm"
      />
      <el-table-column
        label="单位"
        min-width="10%"
        :show-overflow-tooltip="true"
        align="center"
        prop="itmDw"
      >
        <template #default="scope">
          <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
        </template>
      </el-table-column>
      <el-table-column
        label="存放位置"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdCwdm"
      >
        <template #default="scope">
          <dict-tag :options="allCwOptions" :value="scope.row.cjdCwdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="最小包装"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdMinbz"
      />
      <el-table-column
        label="包装数量"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdBzsl"
      />
      <el-table-column
        label="申请数量"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdSqsl"
      />
      <el-table-column
        label="出库数量"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdCksl"
      />
      <el-table-column
        label="出库人员"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="cjdCkry"
      />
      <el-table-column
        label="出库日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cjdCkrq"
        min-width="10%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cjmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="100"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="ckConfirm(scope.row)"
            v-hasPermi="['output:cjmFinish:outputConfirm']"
          >
            出库确认
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="24">
          <el-form-item label="借料单号" prop="cjmDjbh">
            <el-input
              v-model="queryParams.cjmDjbh"
              placeholder="请输入借料单号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="daterangeCjmJlrq"
              :picker-options="pickerOptions"
              size="small"
              :clearable="false"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态标志">
            <el-radio-group v-model="queryParams.cjmZtbz">
              <el-radio
                v-for="dict in cjmZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
                >{{ dict.dictLabel }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 出库确认对话框   -->
    <el-dialog
      :title="title"
      v-model="resultOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="cjdForm"
        :model="cjdForm"
        label-width="88px"
        :rules="cjdFormRules"
      >
        <el-col :span="24">
          <el-form-item label="退料单号" prop="cjdDjbh">
            <el-input v-model="cjdForm.cjdDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="cjdWldm">
            <el-input v-model="cjdForm.cjdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="品名规格" prop="itmPmgg">
            <el-input v-model="cjdForm.itmPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="cjdSqsl">
            <el-input v-model="cjdForm.cjdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存放位置" prop="cjdCwdm">
            <el-select
              v-model="cjdForm.cjdCwdm"
              placeholder="请选择入库类型"
              disabled
            >
              <el-option
                v-for="dict in allCwOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="包装数量" prop="cjdBzsl">
            <el-input type="number" v-model="cjdForm.cjdBzsl" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最小包装" prop="cjdMinbz">
            <el-input v-model="cjdForm.cjdMinbz" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出库数量" prop="cjdCksl">
            <el-input
              v-model="cjdForm.cjdCksl"
              type="number"
              @input="changValue(cjdForm.cjdCksl)"
            />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ckSubmit">确 定</el-button>
        <el-button @click="resultOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCjmOpen,
  getCjmOpen,
  delCjmOpen,
  addCjmOpen,
  updateCjmOpen,
  exportCjmOpen,
  childrenList,
  jlAddList,
  sumitChildren,
  updateCjmTj,
  deleCjm,
  exportCjmMx,
} from "@/api/output/cjmOpen";
import {
  getAllCs,
  getCs,
  listPutStorageAdds,
} from "@/api/putStorage/putStorageAdd";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import { back, check } from "@/api/output/cjmCheck";
import { outOfStock, allOut, postCjm } from "@/api/output/cjmPost";
import { printOrder } from "@/utils/ruoyi";

export default {
  name: "CjmCheck",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      tjFlage: false,
      mxDate: true,
      type1: true,
      //出库确认对话框
      resultOpen: false,
      cjdForm: {},
      cjdFormRules: {
        cjdBzsl: [
          { required: true, message: "请输入包装数量", trigger: "blur" },
        ],
        cjdCksl: [
          { required: true, message: "请输入出库数量", trigger: "blur" },
        ],
      },
      // 选中数组
      ids: [],
      unitFlagOptions: [],
      allCwOptions: [],
      tableH: 250,
      tableHChild: 300,
      tableHAdd: 250,
      tableHAddChild: 300,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      printDiag: false,
      // 总条数
      total: 0,
      total2: 0,
      rowData: null,
      // 对外生产借料开单作业表格数据
      cjmOpenList: [],
      cjmChildrenList: [],
      //存储厂商
      allCsOptions: [],

      //有效存储仓库
      storageOptions: [],
      serachAddList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      opened: false,
      selectioned: [],
      // 查询子项参数
      queryChildParams: {
        pageNum: 1,
        pageSize: 25,
        //仓库代码
        cjmCkdm: null,
        //订单编号
        cjmDjbh: null,
        itmPmgg: null,
        itmWldm: null,
      },
      printDjbh: null,
      printRq: null,
      printCkdm: null,
      printDh: null,
      printRy: null,
      // 状态标志字典
      cjmZtbzOptions: [],
      allStorageOptions: [],
      // // 建立日期时间范围
      // daterangeCjmJlrq: [],
      // 建立日期时间范围
      daterangeCjmJlrq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cjmDjbh: null,
        cjmZtbz: "2",
        cjmJlrq: null,
        cjmTjflag: "1",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cjmDjbh: [
          { required: true, message: "借料单号不能为空", trigger: "blur" },
        ],
        cjmRq: [
          { required: true, message: "借料日期不能为空", trigger: "blur" },
        ],
        cjmCkdm: [
          { required: true, message: "仓库代码不能为空", trigger: "change" },
        ],
        cjmCsdm: [
          { required: true, message: "厂商代码不能为空", trigger: "change" },
        ],
      },
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_post_ztbz").then((response) => {
      this.cjmZtbzOptions = response.data;
    });
    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });
    getAllCs().then((response) => {
      this.allCsOptions = response.data;
      for (let item of this.allCsOptions) {
        item.dictLabel = item.csmCs;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });
  },
  methods: {
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.cjmZtbz == "1" && row.cjmTjflag == "1") {
        return "color:#0fac09";
      }
      //检验
      else if (row.cjmZtbz == "2" && row.cjmTjflag == "1") {
        return "color:#0323af";
      }
      //通过
      else if (row.cjmZtbz == "6" && row.cjmTjflag == "1") {
        return "color:#bb0331";
      }
    },
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.cjdCkry) {
        return "color:#bb0331";
      }
    },
    /** 查询对外生产借料开单作业列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCjmJlrq && "" != this.daterangeCjmJlrq) {
        this.queryParams.params["beginCjmJlrq"] = this.moment(
          this.daterangeCjmJlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endCjmJlrq"] = this.moment(
          this.daterangeCjmJlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listCjmOpen(this.queryParams).then((response) => {
        this.cjmChildrenList = [];
        this.cjmOpenList = [];
        this.cjmOpenList = this.cjmOpenList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRwm(row);
        } else if (this.cjmOpenList != null && this.cjmOpenList.length > 0) {
          this.clickRwm(this.cjmOpenList[0]);
        }
      });
    },

    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        listCjmOpen(this.queryParams).then((response) => {
          this.cjmOpenList = this.cjmOpenList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    printData() {
      this.$print(this.$refs.print).dom.ownerDocument.title =
        "武汉市衡德实业有限公司";
      // console.log( this.$print(this.$refs.print))
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.opened = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cjmId: null,
        cjmDjbh: null,
        cjmRq: new Date(),
        cjmCkdm: null,
        cjmCsdm: null,
        cjmDesc: null,
        cjmTjflag: null,
        cjmNgdesc: null,
        cjmZtbz: "1",
        cjmJlry: null,
        cjmJlrq: null,
        cjmPzry: null,
        cjmPzrq: null,
        cjmGzry: null,
        cjmGzrq: null,
      };
      this.resetForm("form");
    },

    resetCjd() {
      this.cjdForm = {
        cjdDjbh: null,
        cjdWldm: null,
        itmPmgg: null,
        cjdSqsl: null,
        cjdCwdm: null,
        cjdBzsl: null,
        cjdMinbz: null,
        cjdCksl: null,
      };

      this.resetForm("cjdForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.cjmOpenList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCjmJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handlePrint(a) {
      const data = { cjmDjbh: a.cjmDjbh };
      printOrder(
        "/output/cjmOpen/exportProductBorrowTemplate",
        data,
        "对外生产借料单据"
      );
      /*      console.log(a)
      for (let i = 0; i < this.csOptions.length; i++) {
        if (this.csOptions[i].dictValue == a.cjmCsdm) {
          this.printDjbh = this.csOptions[i].dictLabel
          break
        }
      }
      for (let i = 0; i < this.allStorageOptions.length; i++) {
        if (this.allStorageOptions[i].dictValue == a.cjmCkdm) {
          this.printCkdm = this.allStorageOptions[i].dictLabel
          // console.log(this.printCsmc)
          break
        }
      }
      // for (let i = 0; i < this.psTypeOptions.length; i++) {
      //   if (this.psTypeOptions[i].dictValue == a.rwmType) {
      //     this.printType = this.psTypeOptions[i].dictLabel
      //     // console.log(this.printCsmc)
      //     break
      //   }
      // }
      // csOptions psTypeOptions
      // console.log(this.psTypeOptions)
      // this.printDjbh = a.rwmDjbh
      this.printRq = a.cjmGzrq
      this.printDh = a.cjmDjbh
      this.printRy = a.cjmGzry
      // this.printRkrq = a.rwmRkrq
      this.printDiag = true
      // console.log(this.$print)
      // this.$print(this.$refs.print)*/
    },
    clickRwm(row) {
      // //获得选中的详细数据
      this.rowData = row;
      // //获得当前单据的状态
      // this.ids = row.rwmId
      this.type1 = !(row != null && row.cjmTjflag == "1" && row.cjmZtbz == "2");
      if (row != null) {
        this.cjmZtbz = row.cjmZtbz;
      }
      this.queryChildParams.cjmDjbh = row.cjmDjbh;
      //获得选中的详细数据
      this.getRwdDetList(row.cjmDjbh);
    },
    /** 获取RwdDet 数据*/
    getRwdDetList(cjmDjbh) {
      childrenList(cjmDjbh).then((response) => {
        this.cjmChildrenList = response.data;
        this.mxDate = this.cjmChildrenList.length > 0 ? false : true;
      });
    },
    /** 一键出库 */
    handleOutPut() {
      const cjmIds = this.rowData.cjmDjbh;
      allOut(cjmIds).then((response) => {
        this.check_back = false;
        this.msgSuccess("一键出库成功");
        this.queryParams.pageNum = 1;
        this.cjmOpenList = [];
        this.getList();
      });
    },
    /** 过账 */
    handlePost() {
      const cjmIds = this.rowData.cjmDjbh;
      if (cjmIds) {
        this.$confirm(
          '是否确认对外生产借料开单作业编号为"' + cjmIds + '"的数据项进行过账?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            return postCjm(this.rowData);
          })
          .then(() => {
            this.queryParams.pageNum = 1;
            this.cjmOpenList = [];
            this.getList();
            this.msgSuccess("过账成功");
          })
          .catch(() => {});
      } else {
        this.msgError("无过账单据");
      }
    },

    /**  撤回 */
    handleBack() {
      this.$refs["rollbackForm"].validate((valid) => {
        if (valid) {
          back(this.rowData.cjmDjbh, this.rollbackForm.cjdNgdesc).then(
            (response) => {
              this.check_back = false;
              this.msgSuccess("撤回成功");
              this.queryParams.pageNum = 1;
              this.cjmOpenList = [];
              this.getList();
            }
          );
        }
      });
    },

    handleSearch() {
      this.reset();
      this.title = "查询对外生产借料开单作业";
      this.openSearch = true;
    },
    /** 删除按钮操作 */
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有对外生产借料开单作业数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportCjmOpen(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /** 导出明细按钮操作 */
    handleExportMx() {
      const queryParams = this.rowData.cjmDjbh;
      this.$confirm("是否确认导出所有对外生产借料开单作业明细数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportCjmMx(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },

    changValue(value) {
      if (value > this.cjdForm.cjdSqsl || value < 0) {
        this.msgError("请输入0-" + this.cjdForm.cjdSqsl + "的数字");

        this.cjdForm.cjdCksl = this.cjdForm.cjdSqsl;
      }
    },

    //出库确认显示
    ckConfirm(row) {
      this.resetCjd();
      //开始赋值
      this.cjdForm.cjdDjbh = row.cjdDjbh;
      this.cjdForm.cjdWldm = row.cjdWldm;
      this.cjdForm.itmPmgg = row.itmPmgg;
      this.cjdForm.cjdSqsl = row.cjdSqsl;
      this.cjdForm.cjdCwdm = row.cjdCwdm;
      this.cjdForm.cjdMinbz = row.cjdMinbz;
      this.cjdForm.cjdBzsl = row.cjdBzsl;
      this.cjdForm.cjdCksl = row.cjdSqsl;
      this.title = "出库确认";
      this.resultOpen = true;
    },

    ckSubmit() {
      outOfStock(
        this.cjdForm.cjdDjbh,
        this.cjdForm.cjdWldm,
        this.cjdForm.cjdCksl,
        this.cjdForm.cjdBzsl
      ).then((response) => {
        this.resultOpen = false;
        this.getRwdDetList(this.rowData.cjmDjbh);
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
